<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>返回数组的所有子集</title>
</head>

<body>
  <script>
    var subsets = function (nums) {
      let res = [], len = nums.length;
      for (let i = 0; i < (1 << len); i++) {
        let arr = [];
        for (let j = 0; j < len; j++) {
          if (i & (1 << j)) arr.push(nums[j]);
        }
        res.push(arr);
      }
      return res;
    };
    console.log(subsets([1, 2, 3]))
  </script>
</body>

</html>